package com.googlecode.lohr.tools.interpreter;

import lohr.lang.dom.BooleanLiteral;
import lohr.lang.dom.ClosureLiteral;
import lohr.lang.dom.Expression;
import lohr.lang.dom.Literal;
import lohr.lang.dom.NaturalLiteral;
import lohr.lang.dom.StringLiteral;

public abstract class LiteralImpl extends ExpressionImpl {
	public static final LiteralImpl createLiteral(LohrInterpreter interpreter, Literal expression) {
		if (expression instanceof BooleanLiteral) {
			if (BooleanLiteral.FALSE.equals(expression))
				return interpreter.FALSE;
			return interpreter.TRUE;
		}
		if (expression instanceof NaturalLiteral) {
			return new NaturalLiteralImpl(interpreter, expression);
		}
		if (expression instanceof StringLiteral) {
			return new StringLiteralImpl(interpreter, expression);
		}
		if (expression instanceof ClosureLiteral) {
			return new ClosureLiteralImpl(interpreter, expression);
		}
		throw new RuntimeException("Unknown literal type"+expression);
	}
	
	protected LiteralImpl(LohrInterpreter interpreter, Expression expression) {
		super(interpreter, expression);
	}

}
